﻿CREATE PROCEDURE [dbo].[Sys_GetConfigByUserID]
	@user int =-1,
	@moduleID int =-1
AS
	select c.ConfigID,
			  c.Name,
			  c.DataType,
			  c.ConfigLevel,
			  case 
				  when c.ConfigLevel=0 or (c.ConfigLevel=1 and uc.Value is null) then c.Value
				  when c.ConfigLevel=1 and (not (uc.Value is null)) then uc.Value
			  end as Value,
			  c.ModuleID
	from sys_Config c
	left join 
	(select  ConfigID,Value from sys_UserConfig where [UserID]=@user)uc on c.ConfigID=uc.ConfigID and c.ConfigLevel=1
	where @moduleID=-1 or c.ModuleID=@moduleID
	
	
